﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.JointJog.CUiKinJointJogCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using COMMANDPARAMSLib;
using EngineeringInternalExtension;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.CommandParameters;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.JointJog;

public class CUiKinJointJogCmd : TxButtonCommand, ITxSemiModalCommandBehavior
{
  protected CUiKinJointJogEnabler m_enabler;

  public CUiKinJointJogCmd() => this.m_enabler = new CUiKinJointJogEnabler();

  public virtual string Category => JointJogStringTable.CMD_CATEGORY;

  public virtual string Name => JointJogStringTable.CMD_NAME;

  public virtual string Tooltip => JointJogStringTable.CMD_TOOLTIP;

  public virtual string Bitmap => "JointJog.JointJogIcon.bmp";

  public virtual string LargeBitmap => "JointJog.JointJogIcon_LARGE.png";

  public virtual string Description => JointJogStringTable.CMD_DESCRIPTION;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual bool Connect() => true;

  public virtual bool Licensed => TxCommandLicenser.JointJogLicense;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("JointJog");

  bool ITxSemiModalCommandBehavior.StayEnabledInSemiModalMode
  {
    get
    {
      return TxApplicationEx.IsInSpecificMode(new TxApplicationModeEx("KINEMATICS_MOVEMENTS_MODE", true));
    }
  }

  public virtual void Execute(object cmdParams)
  {
    TxPerformanceMeasurementEx.StartMeasureTask("Start JointJog");
    ITxDevice rootDevice = (ITxDevice) null;
    if (cmdParams != null)
    {
      rootDevice = this.GetSingleObjectParameters(cmdParams).Object as ITxDevice;
    }
    else
    {
      TxObjectList items = TxApplication.ActiveSelection.GetItems();
      if (((Collection<ITxObject>) items).Count == 1)
        rootDevice = ((Collection<ITxObject>) items)[0] as ITxDevice;
    }
    if (rootDevice != null)
      new CUiKinJointJogForm().Show(rootDevice);
    TxPerformanceMeasurementEx.StopMeasureTask("Start JointJog");
  }

  internal TxSingleObjectParameters GetSingleObjectParameters(object cmdParams)
  {
    switch (cmdParams)
    {
      case ICoSingleObjectParams singleObjectParams:
        pattern_0 = new TxSingleObjectParameters();
        ITApiObj apiObj = (ITApiObj) null;
        singleObjectParams.GetObj(ref apiObj);
        if (apiObj != null)
        {
          ITxObject objectFromApiObj = this.GetObjectFromApiObj(apiObj);
          pattern_0.Object = objectFromApiObj;
          break;
        }
        break;
    }
    return pattern_0;
  }

  private ITxObject GetObjectFromApiObj(ITApiObj apiObj)
  {
    string str;
    apiObj.DumpToString(ref str);
    ITxObject objectFromApiObj = (ITxObject) null;
    if (str != null)
      objectFromApiObj = TxConvertor.tID2Object(str);
    return objectFromApiObj;
  }
}
